package decrypt.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Some utilities help reading data from files.
 * 
 */
public class Constants
{
    public static final String FILE_DIR = System.getProperty( "user.dir" )
            + "/data/";

    public static final String RSA_PRI_FILENAME = "rsa_priv.bin";

    public static final String RSA_PUB_FILENAME = "rsa_pub.bin";

    public static final String AES_FILENAME = "sess.bin";

    public static final String IV_FILENAME = "iv.bin";

    public static final String TARGET = "hw2.II.html.enc";

    public static final String DECRYPTED_HTML = "hw2.II.html";

    public static byte[] getBytesFromFile( String fileName ) throws IOException {
        File file = new File( FILE_DIR + fileName );
        FileInputStream fis = new FileInputStream( FILE_DIR + fileName );
        byte[] data = new byte[(int) file.length()];
        fis.read( data );
        fis.close();
        return data;
    }

    public static void writeToFile( String s ) throws IOException {

        BufferedWriter out = null;
        try {
            FileWriter fstream = new FileWriter( DECRYPTED_HTML );
            out = new BufferedWriter( fstream );
            out.write( s );
        } catch( IOException e ) {// Catch exception if any
            System.err.println( "Error: " + e.getMessage() );
        } finally {
            if( out != null ) {
                out.close();
            }
        }
    }
}